package com.baturu.mybatisminus;

import org.apache.ibatis.builder.MapperBuilderAssistant;
import org.apache.ibatis.executor.keygen.KeyGenerator;
import org.apache.ibatis.mapping.*;
import org.apache.ibatis.scripting.LanguageDriver;
import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.type.TypeAliasRegistry;
import org.apache.ibatis.type.TypeHandlerRegistry;


public class MockMapperBuilderAssistant extends MapperBuilderAssistant {

    public MockMapperBuilderAssistant() {
        super(new MinusConfiguration(), "resource");
    }

    public MockMapperBuilderAssistant(String resource) {
        super(new MinusConfiguration(), resource);
        ((MinusConfiguration)this.getConfiguration()).setShowGeneratedSql(true);
    }

    @Override
    public MappedStatement addMappedStatement(
            String id,
            SqlSource sqlSource,
            StatementType statementType,
            SqlCommandType sqlCommandType,
            Integer fetchSize,
            Integer timeout,
            String parameterMap,
            Class<?> parameterType,
            String resultMap,
            Class<?> resultType,
            ResultSetType resultSetType,
            boolean flushCache,
            boolean useCache,
            boolean resultOrdered,
            KeyGenerator keyGenerator,
            String keyProperty,
            String keyColumn,
            String databaseId,
            LanguageDriver lang,
            String resultSets) {
        StringBuilder sb = new StringBuilder();
        sb.append("添加MappedStatement---").append("id:").append(id).append("---")
                .append("SqlCommandType:").append(sqlCommandType).append("---")
                .append("parameterType:").append(parameterType != null ? parameterType.getSimpleName() : null).append("---")
                .append("resultType:").append(resultType != null ? resultType.getSimpleName() : null);
        System.out.println(sb.toString());
        return null;
    }

    public Configuration getConfiguration() {
        return new MinusConfiguration() {
            @Override
            public LanguageDriver getDefaultScriptingLanguageInstance() {
                return new XMLLanguageDriver();
            }
        };
    }
}
